{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import featuretools as ft\n",
    "from woodwork.logical_types import Categorical"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>invoice</th>\n",
       "      <th>invoice_date</th>\n",
       "      <th>stock_code</th>\n",
       "      <th>description</th>\n",
       "      <th>quantity</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>85048</td>\n",
       "      <td>15CM CHRISTMAS GLASS BALL 20 LIGHTS</td>\n",
       "      <td>12</td>\n",
       "      <td>6.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>79323P</td>\n",
       "      <td>PINK CHERRY LIGHTS</td>\n",
       "      <td>12</td>\n",
       "      <td>6.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>79323W</td>\n",
       "      <td>WHITE CHERRY LIGHTS</td>\n",
       "      <td>12</td>\n",
       "      <td>6.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>22041</td>\n",
       "      <td>RECORD FRAME 7\" SINGLE SIZE</td>\n",
       "      <td>48</td>\n",
       "      <td>2.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>21232</td>\n",
       "      <td>STRAWBERRY CERAMIC TRINKET BOX</td>\n",
       "      <td>24</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   customer_id invoice        invoice_date stock_code  \\\n",
       "0      13085.0  489434 2009-12-01 07:45:00      85048   \n",
       "1      13085.0  489434 2009-12-01 07:45:00     79323P   \n",
       "2      13085.0  489434 2009-12-01 07:45:00     79323W   \n",
       "3      13085.0  489434 2009-12-01 07:45:00      22041   \n",
       "4      13085.0  489434 2009-12-01 07:45:00      21232   \n",
       "\n",
       "                           description  quantity  price  \n",
       "0  15CM CHRISTMAS GLASS BALL 20 LIGHTS        12   6.95  \n",
       "1                   PINK CHERRY LIGHTS        12   6.75  \n",
       "2                  WHITE CHERRY LIGHTS        12   6.75  \n",
       "3         RECORD FRAME 7\" SINGLE SIZE         48   2.10  \n",
       "4       STRAWBERRY CERAMIC TRINKET BOX        24   1.25  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load data\n",
    "\n",
    "df = pd.read_csv(\"retail.csv\", parse_dates=[\"invoice_date\"])\n",
    "\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>invoice</th>\n",
       "      <th>invoice_date</th>\n",
       "      <th>stock_code</th>\n",
       "      <th>description</th>\n",
       "      <th>quantity</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>741296</th>\n",
       "      <td>15804.0</td>\n",
       "      <td>581585</td>\n",
       "      <td>2011-12-09 12:31:00</td>\n",
       "      <td>22466</td>\n",
       "      <td>FAIRY TALE COTTAGE NIGHT LIGHT</td>\n",
       "      <td>12</td>\n",
       "      <td>1.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>741297</th>\n",
       "      <td>13113.0</td>\n",
       "      <td>581586</td>\n",
       "      <td>2011-12-09 12:49:00</td>\n",
       "      <td>22061</td>\n",
       "      <td>LARGE CAKE STAND  HANGING STRAWBERY</td>\n",
       "      <td>8</td>\n",
       "      <td>2.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>741298</th>\n",
       "      <td>13113.0</td>\n",
       "      <td>581586</td>\n",
       "      <td>2011-12-09 12:49:00</td>\n",
       "      <td>23275</td>\n",
       "      <td>SET OF 3 HANGING OWLS OLLIE BEAK</td>\n",
       "      <td>24</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>741299</th>\n",
       "      <td>13113.0</td>\n",
       "      <td>581586</td>\n",
       "      <td>2011-12-09 12:49:00</td>\n",
       "      <td>21217</td>\n",
       "      <td>RED RETROSPOT ROUND CAKE TINS</td>\n",
       "      <td>24</td>\n",
       "      <td>8.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>741300</th>\n",
       "      <td>13113.0</td>\n",
       "      <td>581586</td>\n",
       "      <td>2011-12-09 12:49:00</td>\n",
       "      <td>20685</td>\n",
       "      <td>DOORMAT RED RETROSPOT</td>\n",
       "      <td>10</td>\n",
       "      <td>7.08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id invoice        invoice_date stock_code  \\\n",
       "741296      15804.0  581585 2011-12-09 12:31:00      22466   \n",
       "741297      13113.0  581586 2011-12-09 12:49:00      22061   \n",
       "741298      13113.0  581586 2011-12-09 12:49:00      23275   \n",
       "741299      13113.0  581586 2011-12-09 12:49:00      21217   \n",
       "741300      13113.0  581586 2011-12-09 12:49:00      20685   \n",
       "\n",
       "                                description  quantity  price  \n",
       "741296       FAIRY TALE COTTAGE NIGHT LIGHT        12   1.95  \n",
       "741297  LARGE CAKE STAND  HANGING STRAWBERY         8   2.95  \n",
       "741298     SET OF 3 HANGING OWLS OLLIE BEAK        24   1.25  \n",
       "741299        RED RETROSPOT ROUND CAKE TINS        24   8.95  \n",
       "741300                DOORMAT RED RETROSPOT        10   7.08  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5410"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# number of customers\n",
    "\n",
    "df[\"customer_id\"].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "40505"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# number of invoices\n",
    "\n",
    "df[\"invoice\"].nunique() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4631"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# number of unique items\n",
    "\n",
    "df[\"stock_code\"].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "741301"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# total data\n",
    "\n",
    "len(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create and entity set\n",
    "\n",
    "es = ft.EntitySet(id=\"data\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\woodwork\\type_sys\\utils.py:40: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\woodwork\\type_sys\\utils.py:40: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\woodwork\\type_sys\\utils.py:40: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\woodwork\\type_sys\\utils.py:40: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\woodwork\\type_sys\\utils.py:40: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\woodwork\\type_sys\\utils.py:40: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Entityset: data\n",
       "  DataFrames:\n",
       "    data [Rows: 741301, Columns: 8]\n",
       "  Relationships:\n",
       "    No relationships"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Add the data to the entity\n",
    "\n",
    "es = es.add_dataframe(\n",
    "    dataframe=df,              # the dataframe with the data\n",
    "    dataframe_name=\"data\",     # unique name to associate with this dataframe\n",
    "    index=\"rows\",              # column name to index the items\n",
    "    make_index=True,           # if true, create a new column with unique values\n",
    "    time_index=\"invoice_date\", # column containing time data\n",
    "    logical_types={\n",
    "        \"customer_id\": Categorical, # the id is numerical, but should be handled as categorical\n",
    "    },\n",
    ")\n",
    "\n",
    "# display the entity set\n",
    "es"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Entityset: data\n",
       "  DataFrames:\n",
       "    data [Rows: 741301, Columns: 8]\n",
       "    invoices [Rows: 40505, Columns: 3]\n",
       "  Relationships:\n",
       "    data.invoice -> invoices.invoice"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a new dataframe indicating its \n",
    "# relationship to the main data\n",
    "\n",
    "# we start with invoice\n",
    "\n",
    "es.normalize_dataframe(\n",
    "    base_dataframe_name=\"data\",     # Datarame name from which to split.\n",
    "    new_dataframe_name=\"invoices\",  # Name of the new dataframe.\n",
    "    index=\"invoice\",                # relationship will be created across this column.\n",
    "    copy_columns=[\"customer_id\"],   # columns to remove from base_dataframe and move to new dataframe.\n",
    ")\n",
    "\n",
    "# display the entity set\n",
    "es"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Entityset: data\n",
       "  DataFrames:\n",
       "    data [Rows: 741301, Columns: 8]\n",
       "    invoices [Rows: 40505, Columns: 3]\n",
       "    customers [Rows: 5410, Columns: 2]\n",
       "  Relationships:\n",
       "    data.invoice -> invoices.invoice\n",
       "    invoices.customer_id -> customers.customer_id"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a new dataframe indicating its \n",
    "# relationship to the previous dataframe\n",
    "\n",
    "# now we work with customers\n",
    "\n",
    "es.normalize_dataframe(\n",
    "    base_dataframe_name=\"invoices\",  # note that we use the df from the previous cell\n",
    "    new_dataframe_name=\"customers\",  # the name of the new df\n",
    "    index=\"customer_id\",             # the column that indicates the relationship\n",
    ")\n",
    "\n",
    "es"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Entityset: data\n",
       "  DataFrames:\n",
       "    data [Rows: 741301, Columns: 8]\n",
       "    invoices [Rows: 40505, Columns: 3]\n",
       "    customers [Rows: 5410, Columns: 2]\n",
       "    items [Rows: 4631, Columns: 2]\n",
       "  Relationships:\n",
       "    data.invoice -> invoices.invoice\n",
       "    invoices.customer_id -> customers.customer_id\n",
       "    data.stock_code -> items.stock_code"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a new dataframe indicating its \n",
    "# relationship to the main data\n",
    "\n",
    "# now we work with individual products\n",
    "\n",
    "es.normalize_dataframe(\n",
    "    base_dataframe_name=\"data\",  # Datarame name from which to split.\n",
    "    new_dataframe_name=\"items\",  # Name of the new dataframe.\n",
    "    index=\"stock_code\",          # relationship will be created across this column.\n",
    ")\n",
    "\n",
    "# display the entity set\n",
    "es"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(741301, 8)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the original data\n",
    "\n",
    "es[\"data\"].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rows</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>invoice</th>\n",
       "      <th>invoice_date</th>\n",
       "      <th>stock_code</th>\n",
       "      <th>description</th>\n",
       "      <th>quantity</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>85048</td>\n",
       "      <td>15CM CHRISTMAS GLASS BALL 20 LIGHTS</td>\n",
       "      <td>12</td>\n",
       "      <td>6.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>79323P</td>\n",
       "      <td>PINK CHERRY LIGHTS</td>\n",
       "      <td>12</td>\n",
       "      <td>6.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>79323W</td>\n",
       "      <td>WHITE CHERRY LIGHTS</td>\n",
       "      <td>12</td>\n",
       "      <td>6.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>22041</td>\n",
       "      <td>RECORD FRAME 7\" SINGLE SIZE</td>\n",
       "      <td>48</td>\n",
       "      <td>2.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>489434</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "      <td>21232</td>\n",
       "      <td>STRAWBERRY CERAMIC TRINKET BOX</td>\n",
       "      <td>24</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   rows customer_id invoice        invoice_date stock_code  \\\n",
       "0     0     13085.0  489434 2009-12-01 07:45:00      85048   \n",
       "1     1     13085.0  489434 2009-12-01 07:45:00     79323P   \n",
       "2     2     13085.0  489434 2009-12-01 07:45:00     79323W   \n",
       "3     3     13085.0  489434 2009-12-01 07:45:00      22041   \n",
       "4     4     13085.0  489434 2009-12-01 07:45:00      21232   \n",
       "\n",
       "                           description  quantity  price  \n",
       "0  15CM CHRISTMAS GLASS BALL 20 LIGHTS        12   6.95  \n",
       "1                   PINK CHERRY LIGHTS        12   6.75  \n",
       "2                  WHITE CHERRY LIGHTS        12   6.75  \n",
       "3         RECORD FRAME 7\" SINGLE SIZE         48   2.10  \n",
       "4       STRAWBERRY CERAMIC TRINKET BOX        24   1.25  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the original data\n",
    "\n",
    "es[\"data\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(40505, 3)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the dataframe with invoice data\n",
    "\n",
    "es[\"invoices\"].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>invoice</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>first_data_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>489434</th>\n",
       "      <td>489434</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489435</th>\n",
       "      <td>489435</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>2009-12-01 07:46:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489436</th>\n",
       "      <td>489436</td>\n",
       "      <td>13078.0</td>\n",
       "      <td>2009-12-01 09:06:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489437</th>\n",
       "      <td>489437</td>\n",
       "      <td>15362.0</td>\n",
       "      <td>2009-12-01 09:08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489438</th>\n",
       "      <td>489438</td>\n",
       "      <td>18102.0</td>\n",
       "      <td>2009-12-01 09:24:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       invoice customer_id     first_data_time\n",
       "489434  489434     13085.0 2009-12-01 07:45:00\n",
       "489435  489435     13085.0 2009-12-01 07:46:00\n",
       "489436  489436     13078.0 2009-12-01 09:06:00\n",
       "489437  489437     15362.0 2009-12-01 09:08:00\n",
       "489438  489438     18102.0 2009-12-01 09:24:00"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the dataframe with invoice data\n",
    "\n",
    "# note that featuretools automatically adds the column \n",
    "# with the first date detected for each invoice\n",
    "\n",
    "es[\"invoices\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5410, 2)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the customers dataframe\n",
    "\n",
    "es[\"customers\"].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>first_invoices_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13085.0</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13078.0</th>\n",
       "      <td>13078.0</td>\n",
       "      <td>2009-12-01 09:06:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15362.0</th>\n",
       "      <td>15362.0</td>\n",
       "      <td>2009-12-01 09:08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18102.0</th>\n",
       "      <td>18102.0</td>\n",
       "      <td>2009-12-01 09:24:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18087.0</th>\n",
       "      <td>18087.0</td>\n",
       "      <td>2009-12-01 09:43:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id first_invoices_time\n",
       "13085.0     13085.0 2009-12-01 07:45:00\n",
       "13078.0     13078.0 2009-12-01 09:06:00\n",
       "15362.0     15362.0 2009-12-01 09:08:00\n",
       "18102.0     18102.0 2009-12-01 09:24:00\n",
       "18087.0     18087.0 2009-12-01 09:43:00"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# customers data\n",
    "\n",
    "# note that featuretools automatically adds the column \n",
    "# with the date for the first invoice for each customer\n",
    "\n",
    "es[\"customers\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4631, 2)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the products\n",
    "\n",
    "es[\"items\"].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>stock_code</th>\n",
       "      <th>first_data_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>85048</th>\n",
       "      <td>85048</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79323P</th>\n",
       "      <td>79323P</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79323W</th>\n",
       "      <td>79323W</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22041</th>\n",
       "      <td>22041</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21232</th>\n",
       "      <td>21232</td>\n",
       "      <td>2009-12-01 07:45:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       stock_code     first_data_time\n",
       "85048       85048 2009-12-01 07:45:00\n",
       "79323P     79323P 2009-12-01 07:45:00\n",
       "79323W     79323W 2009-12-01 07:45:00\n",
       "22041       22041 2009-12-01 07:45:00\n",
       "21232       21232 2009-12-01 07:45:00"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the products\n",
    "\n",
    "# note that featuretools automatically adds the column \n",
    "# with the date for the first invoice for each product\n",
    "\n",
    "es[\"items\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 6.0.1 (20220911.1526)\n",
       " -->\n",
       "<!-- Title: data Pages: 1 -->\n",
       "<svg width=\"495pt\" height=\"371pt\"\n",
       " viewBox=\"0.00 0.00 494.50 371.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 367)\">\n",
       "<title>data</title>\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-367 490.5,-367 490.5,4 -4,4\"/>\n",
       "<!-- data -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>data</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"134,-211.5 134,-362.5 364,-362.5 364,-211.5 134,-211.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"249\" y=\"-347.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">data (741301 rows)</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"134,-339.5 364,-339.5\"/>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-324.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">rows : Integer; index</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-309.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">customer_id : Categorical</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-294.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">invoice : Unknown; foreign_key</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-279.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">invoice_date : Datetime; time_index</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-264.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">stock_code : Categorical; foreign_key</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-249.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">description : Categorical</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-234.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">quantity : Integer</text>\n",
       "<text text-anchor=\"start\" x=\"142\" y=\"-219.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">price : Double</text>\n",
       "</g>\n",
       "<!-- invoices -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>invoices</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"8.5,-98.5 8.5,-174.5 241.5,-174.5 241.5,-98.5 8.5,-98.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"125\" y=\"-159.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">invoices (40505 rows)</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"8.5,-151.5 241.5,-151.5\"/>\n",
       "<text text-anchor=\"start\" x=\"16.5\" y=\"-136.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">invoice : Unknown; index</text>\n",
       "<text text-anchor=\"start\" x=\"16.5\" y=\"-121.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">customer_id : Categorical; foreign_key</text>\n",
       "<text text-anchor=\"start\" x=\"16.5\" y=\"-106.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">first_data_time : Datetime; time_index</text>\n",
       "</g>\n",
       "<!-- data&#45;&gt;invoices -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>data&#45;&gt;invoices</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M187.75,-211.31C187.75,-211.31 187.75,-184.61 187.75,-184.61\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"191.25,-184.61 187.75,-174.61 184.25,-184.61 191.25,-184.61\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.75\" y=\"-186.76\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">invoice</text>\n",
       "</g>\n",
       "<!-- items -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>items</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"259.5,-106 259.5,-167 486.5,-167 486.5,-106 259.5,-106\"/>\n",
       "<text text-anchor=\"middle\" x=\"373\" y=\"-151.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">items (4631 rows)</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"259.5,-144 486.5,-144\"/>\n",
       "<text text-anchor=\"start\" x=\"267.5\" y=\"-128.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">stock_code : Categorical; index</text>\n",
       "<text text-anchor=\"start\" x=\"267.5\" y=\"-113.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">first_data_time : Datetime; time_index</text>\n",
       "</g>\n",
       "<!-- data&#45;&gt;items -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>data&#45;&gt;items</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M311.75,-211.31C311.75,-211.31 311.75,-177.11 311.75,-177.11\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"315.25,-177.11 311.75,-167.11 308.25,-177.11 315.25,-177.11\"/>\n",
       "<text text-anchor=\"middle\" x=\"278.25\" y=\"-198.01\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">stock_code</text>\n",
       "</g>\n",
       "<!-- customers -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>customers</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"0,-0.5 0,-61.5 250,-61.5 250,-0.5 0,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"125\" y=\"-46.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">customers (5410 rows)</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"0,-38.5 250,-38.5\"/>\n",
       "<text text-anchor=\"start\" x=\"8\" y=\"-23.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">customer_id : Categorical; index</text>\n",
       "<text text-anchor=\"start\" x=\"8\" y=\"-8.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">first_invoices_time : Datetime; time_index</text>\n",
       "</g>\n",
       "<!-- invoices&#45;&gt;customers -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>invoices&#45;&gt;customers</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M125,-98.41C125,-98.41 125,-71.76 125,-71.76\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"128.5,-71.76 125,-61.76 121.5,-71.76 128.5,-71.76\"/>\n",
       "<text text-anchor=\"middle\" x=\"90\" y=\"-73.89\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">customer_id</text>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x229c3a918a0>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# display your EntitySet structure graphically\n",
    "\n",
    "es.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "114\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<Feature: COUNT(data)>,\n",
       " <Feature: MAX(data.price)>,\n",
       " <Feature: MAX(data.quantity)>,\n",
       " <Feature: MEAN(data.price)>,\n",
       " <Feature: MEAN(data.quantity)>,\n",
       " <Feature: MIN(data.price)>,\n",
       " <Feature: MIN(data.quantity)>,\n",
       " <Feature: MODE(data.description)>,\n",
       " <Feature: MODE(data.stock_code)>,\n",
       " <Feature: NUM_UNIQUE(data.description)>,\n",
       " <Feature: NUM_UNIQUE(data.stock_code)>,\n",
       " <Feature: SKEW(data.price)>,\n",
       " <Feature: SKEW(data.quantity)>,\n",
       " <Feature: STD(data.price)>,\n",
       " <Feature: STD(data.quantity)>,\n",
       " <Feature: SUM(data.price)>,\n",
       " <Feature: SUM(data.quantity)>,\n",
       " <Feature: DAY(first_invoices_time)>,\n",
       " <Feature: MONTH(first_invoices_time)>,\n",
       " <Feature: WEEKDAY(first_invoices_time)>,\n",
       " <Feature: YEAR(first_invoices_time)>,\n",
       " <Feature: MAX(invoices.COUNT(data))>,\n",
       " <Feature: MAX(invoices.MEAN(data.price))>,\n",
       " <Feature: MAX(invoices.MEAN(data.quantity))>,\n",
       " <Feature: MAX(invoices.MIN(data.price))>,\n",
       " <Feature: MAX(invoices.MIN(data.quantity))>,\n",
       " <Feature: MAX(invoices.NUM_UNIQUE(data.description))>,\n",
       " <Feature: MAX(invoices.NUM_UNIQUE(data.stock_code))>,\n",
       " <Feature: MAX(invoices.SKEW(data.price))>,\n",
       " <Feature: MAX(invoices.SKEW(data.quantity))>,\n",
       " <Feature: MAX(invoices.STD(data.price))>,\n",
       " <Feature: MAX(invoices.STD(data.quantity))>,\n",
       " <Feature: MAX(invoices.SUM(data.price))>,\n",
       " <Feature: MAX(invoices.SUM(data.quantity))>,\n",
       " <Feature: MEAN(invoices.COUNT(data))>,\n",
       " <Feature: MEAN(invoices.MAX(data.price))>,\n",
       " <Feature: MEAN(invoices.MAX(data.quantity))>,\n",
       " <Feature: MEAN(invoices.MEAN(data.price))>,\n",
       " <Feature: MEAN(invoices.MEAN(data.quantity))>,\n",
       " <Feature: MEAN(invoices.MIN(data.price))>,\n",
       " <Feature: MEAN(invoices.MIN(data.quantity))>,\n",
       " <Feature: MEAN(invoices.NUM_UNIQUE(data.description))>,\n",
       " <Feature: MEAN(invoices.NUM_UNIQUE(data.stock_code))>,\n",
       " <Feature: MEAN(invoices.SKEW(data.price))>,\n",
       " <Feature: MEAN(invoices.SKEW(data.quantity))>,\n",
       " <Feature: MEAN(invoices.STD(data.price))>,\n",
       " <Feature: MEAN(invoices.STD(data.quantity))>,\n",
       " <Feature: MEAN(invoices.SUM(data.price))>,\n",
       " <Feature: MEAN(invoices.SUM(data.quantity))>,\n",
       " <Feature: MIN(invoices.COUNT(data))>,\n",
       " <Feature: MIN(invoices.MAX(data.price))>,\n",
       " <Feature: MIN(invoices.MAX(data.quantity))>,\n",
       " <Feature: MIN(invoices.MEAN(data.price))>,\n",
       " <Feature: MIN(invoices.MEAN(data.quantity))>,\n",
       " <Feature: MIN(invoices.NUM_UNIQUE(data.description))>,\n",
       " <Feature: MIN(invoices.NUM_UNIQUE(data.stock_code))>,\n",
       " <Feature: MIN(invoices.SKEW(data.price))>,\n",
       " <Feature: MIN(invoices.SKEW(data.quantity))>,\n",
       " <Feature: MIN(invoices.STD(data.price))>,\n",
       " <Feature: MIN(invoices.STD(data.quantity))>,\n",
       " <Feature: MIN(invoices.SUM(data.price))>,\n",
       " <Feature: MIN(invoices.SUM(data.quantity))>,\n",
       " <Feature: MODE(invoices.DAY(first_data_time))>,\n",
       " <Feature: MODE(invoices.MODE(data.description))>,\n",
       " <Feature: MODE(invoices.MODE(data.stock_code))>,\n",
       " <Feature: MODE(invoices.MONTH(first_data_time))>,\n",
       " <Feature: MODE(invoices.WEEKDAY(first_data_time))>,\n",
       " <Feature: MODE(invoices.YEAR(first_data_time))>,\n",
       " <Feature: NUM_UNIQUE(invoices.DAY(first_data_time))>,\n",
       " <Feature: NUM_UNIQUE(invoices.MODE(data.description))>,\n",
       " <Feature: NUM_UNIQUE(invoices.MODE(data.stock_code))>,\n",
       " <Feature: NUM_UNIQUE(invoices.MONTH(first_data_time))>,\n",
       " <Feature: NUM_UNIQUE(invoices.WEEKDAY(first_data_time))>,\n",
       " <Feature: NUM_UNIQUE(invoices.YEAR(first_data_time))>,\n",
       " <Feature: SKEW(invoices.COUNT(data))>,\n",
       " <Feature: SKEW(invoices.MAX(data.price))>,\n",
       " <Feature: SKEW(invoices.MAX(data.quantity))>,\n",
       " <Feature: SKEW(invoices.MEAN(data.price))>,\n",
       " <Feature: SKEW(invoices.MEAN(data.quantity))>,\n",
       " <Feature: SKEW(invoices.MIN(data.price))>,\n",
       " <Feature: SKEW(invoices.MIN(data.quantity))>,\n",
       " <Feature: SKEW(invoices.NUM_UNIQUE(data.description))>,\n",
       " <Feature: SKEW(invoices.NUM_UNIQUE(data.stock_code))>,\n",
       " <Feature: SKEW(invoices.STD(data.price))>,\n",
       " <Feature: SKEW(invoices.STD(data.quantity))>,\n",
       " <Feature: SKEW(invoices.SUM(data.price))>,\n",
       " <Feature: SKEW(invoices.SUM(data.quantity))>,\n",
       " <Feature: STD(invoices.COUNT(data))>,\n",
       " <Feature: STD(invoices.MAX(data.price))>,\n",
       " <Feature: STD(invoices.MAX(data.quantity))>,\n",
       " <Feature: STD(invoices.MEAN(data.price))>,\n",
       " <Feature: STD(invoices.MEAN(data.quantity))>,\n",
       " <Feature: STD(invoices.MIN(data.price))>,\n",
       " <Feature: STD(invoices.MIN(data.quantity))>,\n",
       " <Feature: STD(invoices.NUM_UNIQUE(data.description))>,\n",
       " <Feature: STD(invoices.NUM_UNIQUE(data.stock_code))>,\n",
       " <Feature: STD(invoices.SKEW(data.price))>,\n",
       " <Feature: STD(invoices.SKEW(data.quantity))>,\n",
       " <Feature: STD(invoices.SUM(data.price))>,\n",
       " <Feature: STD(invoices.SUM(data.quantity))>,\n",
       " <Feature: SUM(invoices.MAX(data.price))>,\n",
       " <Feature: SUM(invoices.MAX(data.quantity))>,\n",
       " <Feature: SUM(invoices.MEAN(data.price))>,\n",
       " <Feature: SUM(invoices.MEAN(data.quantity))>,\n",
       " <Feature: SUM(invoices.MIN(data.price))>,\n",
       " <Feature: SUM(invoices.MIN(data.quantity))>,\n",
       " <Feature: SUM(invoices.NUM_UNIQUE(data.description))>,\n",
       " <Feature: SUM(invoices.NUM_UNIQUE(data.stock_code))>,\n",
       " <Feature: SUM(invoices.SKEW(data.price))>,\n",
       " <Feature: SUM(invoices.SKEW(data.quantity))>,\n",
       " <Feature: SUM(invoices.STD(data.price))>,\n",
       " <Feature: SUM(invoices.STD(data.quantity))>,\n",
       " <Feature: MODE(data.invoices.customer_id)>,\n",
       " <Feature: NUM_UNIQUE(data.invoices.customer_id)>]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Now we can start aggregating the data for each level.\n",
    "\n",
    "# Let's begin with customers\n",
    "\n",
    "feature_matrix, feature_defs = ft.dfs(\n",
    "    entityset=es,                        # the entity set\n",
    "    target_dataframe_name=\"customers\",   # the dataframe for wich to create the features\n",
    "    ignore_columns={                     # columns to ignore when creating features\n",
    "        \"invoices\":[\"invoice\"],\n",
    "        \"data\":[\"customer_id\"],\n",
    "    }\n",
    ")\n",
    "\n",
    "print(len(feature_defs))\n",
    "\n",
    "# display name of created features\n",
    "feature_defs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Feature: MIN(data.price)>,\n",
       " <Feature: MIN(data.quantity)>,\n",
       " <Feature: MODE(data.description)>,\n",
       " <Feature: MODE(data.stock_code)>,\n",
       " <Feature: NUM_UNIQUE(data.description)>]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets display 5 features for the book\n",
    "\n",
    "feature_defs[5:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>COUNT(data)</th>\n",
       "      <th>MAX(data.price)</th>\n",
       "      <th>MAX(data.quantity)</th>\n",
       "      <th>MEAN(data.price)</th>\n",
       "      <th>MEAN(data.quantity)</th>\n",
       "      <th>MIN(data.price)</th>\n",
       "      <th>MIN(data.quantity)</th>\n",
       "      <th>MODE(data.description)</th>\n",
       "      <th>MODE(data.stock_code)</th>\n",
       "      <th>NUM_UNIQUE(data.description)</th>\n",
       "      <th>...</th>\n",
       "      <th>SUM(invoices.MIN(data.price))</th>\n",
       "      <th>SUM(invoices.MIN(data.quantity))</th>\n",
       "      <th>SUM(invoices.NUM_UNIQUE(data.description))</th>\n",
       "      <th>SUM(invoices.NUM_UNIQUE(data.stock_code))</th>\n",
       "      <th>SUM(invoices.SKEW(data.price))</th>\n",
       "      <th>SUM(invoices.SKEW(data.quantity))</th>\n",
       "      <th>SUM(invoices.STD(data.price))</th>\n",
       "      <th>SUM(invoices.STD(data.quantity))</th>\n",
       "      <th>MODE(data.invoices.customer_id)</th>\n",
       "      <th>NUM_UNIQUE(data.invoices.customer_id)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>customer_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13085.0</th>\n",
       "      <td>92</td>\n",
       "      <td>830.12</td>\n",
       "      <td>48.0</td>\n",
       "      <td>12.413587</td>\n",
       "      <td>9.076087</td>\n",
       "      <td>0.55</td>\n",
       "      <td>-48.0</td>\n",
       "      <td>RECORD FRAME 7\" SINGLE SIZE</td>\n",
       "      <td>22041</td>\n",
       "      <td>52</td>\n",
       "      <td>...</td>\n",
       "      <td>839.97</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>5.121775</td>\n",
       "      <td>9.190325</td>\n",
       "      <td>18.102348</td>\n",
       "      <td>71.673954</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13078.0</th>\n",
       "      <td>855</td>\n",
       "      <td>12.75</td>\n",
       "      <td>300.0</td>\n",
       "      <td>3.961193</td>\n",
       "      <td>14.061988</td>\n",
       "      <td>0.19</td>\n",
       "      <td>-14.0</td>\n",
       "      <td>AREA PATROLLED METAL SIGN</td>\n",
       "      <td>82582</td>\n",
       "      <td>165</td>\n",
       "      <td>...</td>\n",
       "      <td>207.15</td>\n",
       "      <td>45.0</td>\n",
       "      <td>845.0</td>\n",
       "      <td>845.0</td>\n",
       "      <td>31.021187</td>\n",
       "      <td>92.081934</td>\n",
       "      <td>182.314131</td>\n",
       "      <td>1137.932892</td>\n",
       "      <td>13078.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15362.0</th>\n",
       "      <td>40</td>\n",
       "      <td>9.95</td>\n",
       "      <td>48.0</td>\n",
       "      <td>3.612000</td>\n",
       "      <td>9.200000</td>\n",
       "      <td>0.21</td>\n",
       "      <td>1.0</td>\n",
       "      <td>BLUE PADDED SOFT MOBILE</td>\n",
       "      <td>20703</td>\n",
       "      <td>38</td>\n",
       "      <td>...</td>\n",
       "      <td>0.86</td>\n",
       "      <td>3.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1.570870</td>\n",
       "      <td>1.976498</td>\n",
       "      <td>5.849501</td>\n",
       "      <td>18.242777</td>\n",
       "      <td>15362.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18102.0</th>\n",
       "      <td>1068</td>\n",
       "      <td>3580.80</td>\n",
       "      <td>1008.0</td>\n",
       "      <td>10.831367</td>\n",
       "      <td>175.196629</td>\n",
       "      <td>0.27</td>\n",
       "      <td>-324.0</td>\n",
       "      <td>CREAM HEART CARD HOLDER</td>\n",
       "      <td>22189</td>\n",
       "      <td>415</td>\n",
       "      <td>...</td>\n",
       "      <td>7858.33</td>\n",
       "      <td>17709.0</td>\n",
       "      <td>1050.0</td>\n",
       "      <td>1050.0</td>\n",
       "      <td>77.785954</td>\n",
       "      <td>29.334878</td>\n",
       "      <td>216.812404</td>\n",
       "      <td>7368.950460</td>\n",
       "      <td>18102.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18087.0</th>\n",
       "      <td>95</td>\n",
       "      <td>852.80</td>\n",
       "      <td>3906.0</td>\n",
       "      <td>11.971368</td>\n",
       "      <td>78.189474</td>\n",
       "      <td>0.36</td>\n",
       "      <td>-96.0</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>85123A</td>\n",
       "      <td>48</td>\n",
       "      <td>...</td>\n",
       "      <td>883.90</td>\n",
       "      <td>4162.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>7.420477</td>\n",
       "      <td>7.636412</td>\n",
       "      <td>32.169504</td>\n",
       "      <td>194.088519</td>\n",
       "      <td>18087.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 114 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             COUNT(data)  MAX(data.price)  MAX(data.quantity)  \\\n",
       "customer_id                                                     \n",
       "13085.0               92           830.12                48.0   \n",
       "13078.0              855            12.75               300.0   \n",
       "15362.0               40             9.95                48.0   \n",
       "18102.0             1068          3580.80              1008.0   \n",
       "18087.0               95           852.80              3906.0   \n",
       "\n",
       "             MEAN(data.price)  MEAN(data.quantity)  MIN(data.price)  \\\n",
       "customer_id                                                           \n",
       "13085.0             12.413587             9.076087             0.55   \n",
       "13078.0              3.961193            14.061988             0.19   \n",
       "15362.0              3.612000             9.200000             0.21   \n",
       "18102.0             10.831367           175.196629             0.27   \n",
       "18087.0             11.971368            78.189474             0.36   \n",
       "\n",
       "             MIN(data.quantity)              MODE(data.description)  \\\n",
       "customer_id                                                           \n",
       "13085.0                   -48.0        RECORD FRAME 7\" SINGLE SIZE    \n",
       "13078.0                   -14.0           AREA PATROLLED METAL SIGN   \n",
       "15362.0                     1.0             BLUE PADDED SOFT MOBILE   \n",
       "18102.0                  -324.0             CREAM HEART CARD HOLDER   \n",
       "18087.0                   -96.0  WHITE HANGING HEART T-LIGHT HOLDER   \n",
       "\n",
       "            MODE(data.stock_code)  NUM_UNIQUE(data.description)  ...  \\\n",
       "customer_id                                                      ...   \n",
       "13085.0                     22041                            52  ...   \n",
       "13078.0                     82582                           165  ...   \n",
       "15362.0                     20703                            38  ...   \n",
       "18102.0                     22189                           415  ...   \n",
       "18087.0                    85123A                            48  ...   \n",
       "\n",
       "             SUM(invoices.MIN(data.price))  SUM(invoices.MIN(data.quantity))  \\\n",
       "customer_id                                                                    \n",
       "13085.0                             839.97                              -3.0   \n",
       "13078.0                             207.15                              45.0   \n",
       "15362.0                               0.86                               3.0   \n",
       "18102.0                            7858.33                           17709.0   \n",
       "18087.0                             883.90                            4162.0   \n",
       "\n",
       "             SUM(invoices.NUM_UNIQUE(data.description))  \\\n",
       "customer_id                                               \n",
       "13085.0                                            92.0   \n",
       "13078.0                                           845.0   \n",
       "15362.0                                            40.0   \n",
       "18102.0                                          1050.0   \n",
       "18087.0                                            95.0   \n",
       "\n",
       "             SUM(invoices.NUM_UNIQUE(data.stock_code))  \\\n",
       "customer_id                                              \n",
       "13085.0                                           92.0   \n",
       "13078.0                                          845.0   \n",
       "15362.0                                           40.0   \n",
       "18102.0                                         1050.0   \n",
       "18087.0                                           95.0   \n",
       "\n",
       "             SUM(invoices.SKEW(data.price))  \\\n",
       "customer_id                                   \n",
       "13085.0                            5.121775   \n",
       "13078.0                           31.021187   \n",
       "15362.0                            1.570870   \n",
       "18102.0                           77.785954   \n",
       "18087.0                            7.420477   \n",
       "\n",
       "             SUM(invoices.SKEW(data.quantity))  SUM(invoices.STD(data.price))  \\\n",
       "customer_id                                                                     \n",
       "13085.0                               9.190325                      18.102348   \n",
       "13078.0                              92.081934                     182.314131   \n",
       "15362.0                               1.976498                       5.849501   \n",
       "18102.0                              29.334878                     216.812404   \n",
       "18087.0                               7.636412                      32.169504   \n",
       "\n",
       "            SUM(invoices.STD(data.quantity)) MODE(data.invoices.customer_id)  \\\n",
       "customer_id                                                                    \n",
       "13085.0                            71.673954                         13085.0   \n",
       "13078.0                          1137.932892                         13078.0   \n",
       "15362.0                            18.242777                         15362.0   \n",
       "18102.0                          7368.950460                         18102.0   \n",
       "18087.0                           194.088519                         18087.0   \n",
       "\n",
       "            NUM_UNIQUE(data.invoices.customer_id)  \n",
       "customer_id                                        \n",
       "13085.0                                         1  \n",
       "13078.0                                         1  \n",
       "15362.0                                         1  \n",
       "18102.0                                         1  \n",
       "18087.0                                         1  \n",
       "\n",
       "[5 rows x 114 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe with the new features\n",
    "\n",
    "feature_matrix.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MIN(data.price)</th>\n",
       "      <th>MIN(data.quantity)</th>\n",
       "      <th>MODE(data.description)</th>\n",
       "      <th>MODE(data.stock_code)</th>\n",
       "      <th>NUM_UNIQUE(data.description)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>customer_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13085.0</th>\n",
       "      <td>0.55</td>\n",
       "      <td>-48.0</td>\n",
       "      <td>RECORD FRAME 7\" SINGLE SIZE</td>\n",
       "      <td>22041</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13078.0</th>\n",
       "      <td>0.19</td>\n",
       "      <td>-14.0</td>\n",
       "      <td>AREA PATROLLED METAL SIGN</td>\n",
       "      <td>82582</td>\n",
       "      <td>165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15362.0</th>\n",
       "      <td>0.21</td>\n",
       "      <td>1.0</td>\n",
       "      <td>BLUE PADDED SOFT MOBILE</td>\n",
       "      <td>20703</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18102.0</th>\n",
       "      <td>0.27</td>\n",
       "      <td>-324.0</td>\n",
       "      <td>CREAM HEART CARD HOLDER</td>\n",
       "      <td>22189</td>\n",
       "      <td>415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18087.0</th>\n",
       "      <td>0.36</td>\n",
       "      <td>-96.0</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>85123A</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             MIN(data.price)  MIN(data.quantity)  \\\n",
       "customer_id                                        \n",
       "13085.0                 0.55               -48.0   \n",
       "13078.0                 0.19               -14.0   \n",
       "15362.0                 0.21                 1.0   \n",
       "18102.0                 0.27              -324.0   \n",
       "18087.0                 0.36               -96.0   \n",
       "\n",
       "                         MODE(data.description) MODE(data.stock_code)  \\\n",
       "customer_id                                                             \n",
       "13085.0            RECORD FRAME 7\" SINGLE SIZE                  22041   \n",
       "13078.0               AREA PATROLLED METAL SIGN                 82582   \n",
       "15362.0                 BLUE PADDED SOFT MOBILE                 20703   \n",
       "18102.0                 CREAM HEART CARD HOLDER                 22189   \n",
       "18087.0      WHITE HANGING HEART T-LIGHT HOLDER                85123A   \n",
       "\n",
       "             NUM_UNIQUE(data.description)  \n",
       "customer_id                                \n",
       "13085.0                                52  \n",
       "13078.0                               165  \n",
       "15362.0                                38  \n",
       "18102.0                               415  \n",
       "18087.0                                48  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_matrix[feature_matrix.columns[5:10]].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5410, 114)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_matrix.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<Feature: customer_id>,\n",
       " <Feature: COUNT(data)>,\n",
       " <Feature: MAX(data.price)>,\n",
       " <Feature: MAX(data.quantity)>,\n",
       " <Feature: MEAN(data.price)>,\n",
       " <Feature: MEAN(data.quantity)>,\n",
       " <Feature: MIN(data.price)>,\n",
       " <Feature: MIN(data.quantity)>,\n",
       " <Feature: MODE(data.description)>,\n",
       " <Feature: MODE(data.stock_code)>,\n",
       " <Feature: NUM_UNIQUE(data.description)>,\n",
       " <Feature: NUM_UNIQUE(data.stock_code)>,\n",
       " <Feature: SKEW(data.price)>,\n",
       " <Feature: SKEW(data.quantity)>,\n",
       " <Feature: STD(data.price)>,\n",
       " <Feature: STD(data.quantity)>,\n",
       " <Feature: SUM(data.price)>,\n",
       " <Feature: SUM(data.quantity)>,\n",
       " <Feature: DAY(first_data_time)>,\n",
       " <Feature: MONTH(first_data_time)>,\n",
       " <Feature: WEEKDAY(first_data_time)>,\n",
       " <Feature: YEAR(first_data_time)>]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We can now create features at invoice level\n",
    "\n",
    "feature_matrix, feature_defs = ft.dfs(\n",
    "    entityset=es,                      # the entity set\n",
    "    target_dataframe_name=\"invoices\",  # the dataframe for wich to create the features\n",
    "    ignore_columns = {                 # columns to ignore when creating features\n",
    "        \"data\": [\"customer_id\"],\n",
    "    }, \n",
    "    max_depth = 1,\n",
    ")\n",
    "\n",
    "print(len(feature_defs))\n",
    "\n",
    "# display name of created features\n",
    "feature_defs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>COUNT(data)</th>\n",
       "      <th>MAX(data.price)</th>\n",
       "      <th>MAX(data.quantity)</th>\n",
       "      <th>MEAN(data.price)</th>\n",
       "      <th>MEAN(data.quantity)</th>\n",
       "      <th>MIN(data.price)</th>\n",
       "      <th>MIN(data.quantity)</th>\n",
       "      <th>MODE(data.description)</th>\n",
       "      <th>MODE(data.stock_code)</th>\n",
       "      <th>...</th>\n",
       "      <th>SKEW(data.price)</th>\n",
       "      <th>SKEW(data.quantity)</th>\n",
       "      <th>STD(data.price)</th>\n",
       "      <th>STD(data.quantity)</th>\n",
       "      <th>SUM(data.price)</th>\n",
       "      <th>SUM(data.quantity)</th>\n",
       "      <th>DAY(first_data_time)</th>\n",
       "      <th>MONTH(first_data_time)</th>\n",
       "      <th>WEEKDAY(first_data_time)</th>\n",
       "      <th>YEAR(first_data_time)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invoice</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>489434</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>8</td>\n",
       "      <td>6.95</td>\n",
       "      <td>48.0</td>\n",
       "      <td>4.081250</td>\n",
       "      <td>20.750000</td>\n",
       "      <td>1.25</td>\n",
       "      <td>10.0</td>\n",
       "      <td>WHITE CHERRY LIGHTS</td>\n",
       "      <td>21232</td>\n",
       "      <td>...</td>\n",
       "      <td>0.005779</td>\n",
       "      <td>1.609110</td>\n",
       "      <td>2.721205</td>\n",
       "      <td>12.646287</td>\n",
       "      <td>32.65</td>\n",
       "      <td>166.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489435</th>\n",
       "      <td>13085.0</td>\n",
       "      <td>4</td>\n",
       "      <td>3.75</td>\n",
       "      <td>24.0</td>\n",
       "      <td>2.625000</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>1.65</td>\n",
       "      <td>12.0</td>\n",
       "      <td>CAT BOWL</td>\n",
       "      <td>22195</td>\n",
       "      <td>...</td>\n",
       "      <td>0.516958</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.861684</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>10.50</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489436</th>\n",
       "      <td>13078.0</td>\n",
       "      <td>19</td>\n",
       "      <td>8.50</td>\n",
       "      <td>24.0</td>\n",
       "      <td>3.730526</td>\n",
       "      <td>10.157895</td>\n",
       "      <td>1.25</td>\n",
       "      <td>2.0</td>\n",
       "      <td>PEACE WOODEN BLOCK LETTERS</td>\n",
       "      <td>21181</td>\n",
       "      <td>...</td>\n",
       "      <td>0.585934</td>\n",
       "      <td>0.484434</td>\n",
       "      <td>2.215269</td>\n",
       "      <td>5.899747</td>\n",
       "      <td>70.88</td>\n",
       "      <td>193.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489437</th>\n",
       "      <td>15362.0</td>\n",
       "      <td>23</td>\n",
       "      <td>9.95</td>\n",
       "      <td>12.0</td>\n",
       "      <td>3.628261</td>\n",
       "      <td>6.304348</td>\n",
       "      <td>0.65</td>\n",
       "      <td>1.0</td>\n",
       "      <td>BLUE PADDED SOFT MOBILE</td>\n",
       "      <td>10002</td>\n",
       "      <td>...</td>\n",
       "      <td>0.891079</td>\n",
       "      <td>0.465628</td>\n",
       "      <td>2.697424</td>\n",
       "      <td>4.149861</td>\n",
       "      <td>83.45</td>\n",
       "      <td>145.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489438</th>\n",
       "      <td>18102.0</td>\n",
       "      <td>17</td>\n",
       "      <td>6.40</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2.591176</td>\n",
       "      <td>48.588235</td>\n",
       "      <td>0.98</td>\n",
       "      <td>28.0</td>\n",
       "      <td>CARROT CHARLIE+LOLA COASTER SET</td>\n",
       "      <td>20711</td>\n",
       "      <td>...</td>\n",
       "      <td>1.912915</td>\n",
       "      <td>-0.645841</td>\n",
       "      <td>1.540588</td>\n",
       "      <td>14.013649</td>\n",
       "      <td>44.05</td>\n",
       "      <td>826.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id  COUNT(data)  MAX(data.price)  MAX(data.quantity)  \\\n",
       "invoice                                                                 \n",
       "489434      13085.0            8             6.95                48.0   \n",
       "489435      13085.0            4             3.75                24.0   \n",
       "489436      13078.0           19             8.50                24.0   \n",
       "489437      15362.0           23             9.95                12.0   \n",
       "489438      18102.0           17             6.40                60.0   \n",
       "\n",
       "         MEAN(data.price)  MEAN(data.quantity)  MIN(data.price)  \\\n",
       "invoice                                                           \n",
       "489434           4.081250            20.750000             1.25   \n",
       "489435           2.625000            15.000000             1.65   \n",
       "489436           3.730526            10.157895             1.25   \n",
       "489437           3.628261             6.304348             0.65   \n",
       "489438           2.591176            48.588235             0.98   \n",
       "\n",
       "         MIN(data.quantity)           MODE(data.description)  \\\n",
       "invoice                                                        \n",
       "489434                 10.0              WHITE CHERRY LIGHTS   \n",
       "489435                 12.0                        CAT BOWL    \n",
       "489436                  2.0       PEACE WOODEN BLOCK LETTERS   \n",
       "489437                  1.0          BLUE PADDED SOFT MOBILE   \n",
       "489438                 28.0  CARROT CHARLIE+LOLA COASTER SET   \n",
       "\n",
       "        MODE(data.stock_code)  ...  SKEW(data.price)  SKEW(data.quantity)  \\\n",
       "invoice                        ...                                          \n",
       "489434                  21232  ...          0.005779             1.609110   \n",
       "489435                  22195  ...          0.516958             2.000000   \n",
       "489436                  21181  ...          0.585934             0.484434   \n",
       "489437                  10002  ...          0.891079             0.465628   \n",
       "489438                  20711  ...          1.912915            -0.645841   \n",
       "\n",
       "         STD(data.price)  STD(data.quantity)  SUM(data.price)  \\\n",
       "invoice                                                         \n",
       "489434          2.721205           12.646287            32.65   \n",
       "489435          0.861684            6.000000            10.50   \n",
       "489436          2.215269            5.899747            70.88   \n",
       "489437          2.697424            4.149861            83.45   \n",
       "489438          1.540588           14.013649            44.05   \n",
       "\n",
       "         SUM(data.quantity)  DAY(first_data_time)  MONTH(first_data_time)  \\\n",
       "invoice                                                                     \n",
       "489434                166.0                     1                      12   \n",
       "489435                 60.0                     1                      12   \n",
       "489436                193.0                     1                      12   \n",
       "489437                145.0                     1                      12   \n",
       "489438                826.0                     1                      12   \n",
       "\n",
       "        WEEKDAY(first_data_time) YEAR(first_data_time)  \n",
       "invoice                                                 \n",
       "489434                         1                  2009  \n",
       "489435                         1                  2009  \n",
       "489436                         1                  2009  \n",
       "489437                         1                  2009  \n",
       "489438                         1                  2009  \n",
       "\n",
       "[5 rows x 22 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe with the new features\n",
    "\n",
    "feature_matrix.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(40505, 22)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_matrix.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Built 19 features\n",
      "Elapsed: 00:00 | Progress:   0%|                                                                                       "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x00000229B3398F70> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x00000229B3398670> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x00000229B3398040> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x00000229B3398790> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "C:\\Users\\Sole\\Documents\\Repositories\\envs\\fsml\\lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x00000229B3399090> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Elapsed: 00:02 | Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████\n",
      "19\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<Feature: COUNT(data)>,\n",
       " <Feature: MAX(data.price)>,\n",
       " <Feature: MAX(data.quantity)>,\n",
       " <Feature: MEAN(data.price)>,\n",
       " <Feature: MEAN(data.quantity)>,\n",
       " <Feature: MIN(data.price)>,\n",
       " <Feature: MIN(data.quantity)>,\n",
       " <Feature: MODE(data.description)>,\n",
       " <Feature: NUM_UNIQUE(data.description)>,\n",
       " <Feature: SKEW(data.price)>,\n",
       " <Feature: SKEW(data.quantity)>,\n",
       " <Feature: STD(data.price)>,\n",
       " <Feature: STD(data.quantity)>,\n",
       " <Feature: SUM(data.price)>,\n",
       " <Feature: SUM(data.quantity)>,\n",
       " <Feature: DAY(first_data_time)>,\n",
       " <Feature: MONTH(first_data_time)>,\n",
       " <Feature: WEEKDAY(first_data_time)>,\n",
       " <Feature: YEAR(first_data_time)>]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Now we aggregate data at product level\n",
    "\n",
    "feature_matrix, feature_defs = ft.dfs(\n",
    "    entityset=es,                    # the entity set\n",
    "    target_dataframe_name=\"items\",   # the dataframe for wich to create the features\n",
    "    ignore_columns = {               # columns to ignore when creating features\n",
    "        \"data\": [\"customer_id\"]\n",
    "    }, \n",
    "    verbose=True,\n",
    "    max_depth = 1,\n",
    ")\n",
    "\n",
    "print(len(feature_defs))\n",
    "\n",
    "# display name of created features\n",
    "feature_defs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>COUNT(data)</th>\n",
       "      <th>MAX(data.price)</th>\n",
       "      <th>MAX(data.quantity)</th>\n",
       "      <th>MEAN(data.price)</th>\n",
       "      <th>MEAN(data.quantity)</th>\n",
       "      <th>MIN(data.price)</th>\n",
       "      <th>MIN(data.quantity)</th>\n",
       "      <th>MODE(data.description)</th>\n",
       "      <th>NUM_UNIQUE(data.description)</th>\n",
       "      <th>SKEW(data.price)</th>\n",
       "      <th>SKEW(data.quantity)</th>\n",
       "      <th>STD(data.price)</th>\n",
       "      <th>STD(data.quantity)</th>\n",
       "      <th>SUM(data.price)</th>\n",
       "      <th>SUM(data.quantity)</th>\n",
       "      <th>DAY(first_data_time)</th>\n",
       "      <th>MONTH(first_data_time)</th>\n",
       "      <th>WEEKDAY(first_data_time)</th>\n",
       "      <th>YEAR(first_data_time)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>85048</th>\n",
       "      <td>478</td>\n",
       "      <td>7.95</td>\n",
       "      <td>64.0</td>\n",
       "      <td>7.761715</td>\n",
       "      <td>4.677824</td>\n",
       "      <td>6.95</td>\n",
       "      <td>-12.0</td>\n",
       "      <td>15CM CHRISTMAS GLASS BALL 20 LIGHTS</td>\n",
       "      <td>1</td>\n",
       "      <td>-1.599725</td>\n",
       "      <td>3.999000</td>\n",
       "      <td>0.391349</td>\n",
       "      <td>7.230611</td>\n",
       "      <td>3710.10</td>\n",
       "      <td>2236.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79323P</th>\n",
       "      <td>305</td>\n",
       "      <td>6.75</td>\n",
       "      <td>72.0</td>\n",
       "      <td>6.408361</td>\n",
       "      <td>4.173770</td>\n",
       "      <td>4.65</td>\n",
       "      <td>-61.0</td>\n",
       "      <td>PINK CHERRY LIGHTS</td>\n",
       "      <td>1</td>\n",
       "      <td>-1.117316</td>\n",
       "      <td>0.662425</td>\n",
       "      <td>0.567605</td>\n",
       "      <td>14.070288</td>\n",
       "      <td>1954.55</td>\n",
       "      <td>1273.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79323W</th>\n",
       "      <td>429</td>\n",
       "      <td>6.75</td>\n",
       "      <td>48.0</td>\n",
       "      <td>6.377506</td>\n",
       "      <td>3.648019</td>\n",
       "      <td>4.25</td>\n",
       "      <td>-51.0</td>\n",
       "      <td>WHITE CHERRY LIGHTS</td>\n",
       "      <td>2</td>\n",
       "      <td>-1.009456</td>\n",
       "      <td>0.161517</td>\n",
       "      <td>0.594396</td>\n",
       "      <td>12.283437</td>\n",
       "      <td>2735.95</td>\n",
       "      <td>1565.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22041</th>\n",
       "      <td>325</td>\n",
       "      <td>4.96</td>\n",
       "      <td>240.0</td>\n",
       "      <td>2.450000</td>\n",
       "      <td>21.587692</td>\n",
       "      <td>2.10</td>\n",
       "      <td>-24.0</td>\n",
       "      <td>RECORD FRAME 7\" SINGLE SIZE</td>\n",
       "      <td>1</td>\n",
       "      <td>4.379484</td>\n",
       "      <td>3.064706</td>\n",
       "      <td>0.376132</td>\n",
       "      <td>30.553270</td>\n",
       "      <td>796.25</td>\n",
       "      <td>7016.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21232</th>\n",
       "      <td>1984</td>\n",
       "      <td>2.46</td>\n",
       "      <td>504.0</td>\n",
       "      <td>1.238226</td>\n",
       "      <td>15.760585</td>\n",
       "      <td>1.06</td>\n",
       "      <td>-144.0</td>\n",
       "      <td>STRAWBERRY CERAMIC TRINKET BOX</td>\n",
       "      <td>2</td>\n",
       "      <td>7.769322</td>\n",
       "      <td>5.533837</td>\n",
       "      <td>0.107221</td>\n",
       "      <td>30.344395</td>\n",
       "      <td>2456.64</td>\n",
       "      <td>31269.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            COUNT(data)  MAX(data.price)  MAX(data.quantity)  \\\n",
       "stock_code                                                     \n",
       "85048               478             7.95                64.0   \n",
       "79323P              305             6.75                72.0   \n",
       "79323W              429             6.75                48.0   \n",
       "22041               325             4.96               240.0   \n",
       "21232              1984             2.46               504.0   \n",
       "\n",
       "            MEAN(data.price)  MEAN(data.quantity)  MIN(data.price)  \\\n",
       "stock_code                                                           \n",
       "85048               7.761715             4.677824             6.95   \n",
       "79323P              6.408361             4.173770             4.65   \n",
       "79323W              6.377506             3.648019             4.25   \n",
       "22041               2.450000            21.587692             2.10   \n",
       "21232               1.238226            15.760585             1.06   \n",
       "\n",
       "            MIN(data.quantity)               MODE(data.description)  \\\n",
       "stock_code                                                            \n",
       "85048                    -12.0  15CM CHRISTMAS GLASS BALL 20 LIGHTS   \n",
       "79323P                   -61.0                   PINK CHERRY LIGHTS   \n",
       "79323W                   -51.0                  WHITE CHERRY LIGHTS   \n",
       "22041                    -24.0         RECORD FRAME 7\" SINGLE SIZE    \n",
       "21232                   -144.0       STRAWBERRY CERAMIC TRINKET BOX   \n",
       "\n",
       "            NUM_UNIQUE(data.description)  SKEW(data.price)  \\\n",
       "stock_code                                                   \n",
       "85048                                  1         -1.599725   \n",
       "79323P                                 1         -1.117316   \n",
       "79323W                                 2         -1.009456   \n",
       "22041                                  1          4.379484   \n",
       "21232                                  2          7.769322   \n",
       "\n",
       "            SKEW(data.quantity)  STD(data.price)  STD(data.quantity)  \\\n",
       "stock_code                                                             \n",
       "85048                  3.999000         0.391349            7.230611   \n",
       "79323P                 0.662425         0.567605           14.070288   \n",
       "79323W                 0.161517         0.594396           12.283437   \n",
       "22041                  3.064706         0.376132           30.553270   \n",
       "21232                  5.533837         0.107221           30.344395   \n",
       "\n",
       "            SUM(data.price)  SUM(data.quantity) DAY(first_data_time)  \\\n",
       "stock_code                                                             \n",
       "85048               3710.10              2236.0                    1   \n",
       "79323P              1954.55              1273.0                    1   \n",
       "79323W              2735.95              1565.0                    1   \n",
       "22041                796.25              7016.0                    1   \n",
       "21232               2456.64             31269.0                    1   \n",
       "\n",
       "           MONTH(first_data_time) WEEKDAY(first_data_time)  \\\n",
       "stock_code                                                   \n",
       "85048                          12                        1   \n",
       "79323P                         12                        1   \n",
       "79323W                         12                        1   \n",
       "22041                          12                        1   \n",
       "21232                          12                        1   \n",
       "\n",
       "           YEAR(first_data_time)  \n",
       "stock_code                        \n",
       "85048                       2009  \n",
       "79323P                      2009  \n",
       "79323W                      2009  \n",
       "22041                       2009  \n",
       "21232                       2009  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_matrix.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fsml",
   "language": "python",
   "name": "fsml"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": "block",
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
